<template>
	<view class="sendPartyWp">
		<view v-for="(item,index) in sendPartyList" :key="index">
			<partyItem :item="item" @handleItem='handleItem' @handleBtn="handleItem" btnName="发布组局">

			</partyItem>
		</view>
		<nodata v-if="!sendPartyList || sendPartyList.length==0" nodataText="暂时没有组局"
			nodataImgUrl="https://file.casugn.com/storecompcard/temp/空页面@2x(14)_1681113729843.png">
		</nodata>
		<u-datetime-picker :show="showPicker" v-model="pickerTime" mode="year-month" closeOnClickOverlay
			@confirm="confirm" @cancel="closePicker" @change="changeHandler" @close="closePicker"></u-datetime-picker>
	</view>
</template>

<script>
	import partyItem from '@/pagesParty/components/partyItem/partyItem.vue'
	import nodata from '@/components/nodata/nodata.vue'
	import {
		mapGetters
	} from 'vuex'
	export default {
		components: {
			partyItem,
			nodata
		},
		data() {
			return {
				month: '',
				showPicker: false,
				pickerTime: Number(new Date()),
				queryTime: null,
				sendPartyList: [],
				//子组件传值 要删除的项
				delItem: null,
				//删除弹框
				delModel: false,
				pageNo: 1,
				pageSize: 20,
				total: 0,
				options1: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c',
						width: '100rpx',
						height: '100rpx',
						borderRadius: '50%',
						fontSize: '28rpx',
						textAlign: 'center',
						marginRight: '30rpx'

					}
				}],


			};
		},
		computed: {
			...mapGetters(['userInfo'])
		},
		created() {
			// this.nowTime()
		},
		onShow() {
			this.showPicker = false
			this.delModel = false
			this.resetList()
		},
		onPullDownRefresh() {
			// this.nowTime()
			this.resetList()
		},
		onReachBottom() {
			if (this.total <= this.pageNo * this.pageSize) {
				uni.showToast({
					title: '没有更多数据',
					icon: 'none'
				})
				return
			} else {
				this.pageNo++
				this.queryList()
			}

		},
		methods: {
			resetList() {
				uni.showLoading({
					title: '加载中'
				})
				this.sendPartyList = []
				this.total = 0
				this.pageNo = 1
				this.queryList()
			},
			//获取当月时间
			nowTime() {
				let now = new Date();
				this.month = now.getMonth() + 1
				const timeFormat = uni.$u.timeFormat
				let str = timeFormat(now, 'yyyy-mm')
				//设定为当月一号
				str = str + '-01'
				console.log(str);
				this.queryTime = str
			},
			//选择时间
			chooseTime() {
				this.showPicker = true
			},
			closePicker() {
				this.showPicker = false
			},
			//时间选择改变
			changeHandler(e) {
				const timeFormat = uni.$u.timeFormat
				let str = timeFormat(e.value, 'yyyy-mm')
				//设定为当月一号
				str = str + '-01'
				console.log(str);
				this.queryTime = str
			},
			confirm(e) {
				const timeFormat = uni.$u.timeFormat
				let str = timeFormat(e.value, 'yyyy-mm')
				let aa = str.split('-')[1].split("")
				if (aa[0] == 0) {
					this.month = aa[1]
				} else {
					this.month = aa[0] + aa[1]
				}
				//设定为当月一号
				str = str + '-01'
				console.log(str);
				this.queryTime = str
				this.showPicker = false
				this.resetList()
			},
			//查询列表信息
			async queryList() {

				let params = {
					category: 1, //1：我发布 
					openId: this.userInfo.openId,
					status: 0, // 0:待发布
					// date: this.queryTime,
					pageNo: this.pageNo,
					pageSize: this.pageSize
				}
				let res = await this.$api.queryReleaseGroupPage(params)
				if (res.success) {
					console.log(res.result.records, '草稿箱内容');
					this.sendPartyList = [...this.sendPartyList, ...res.result.records]
					this.total = res.result.total
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
					this.sendPartyList = []
				}
				uni.stopPullDownRefresh()
			},
			showModel(
				item
			) {
				this.delItem = item
				this.delModel = true
			},
			async handleDelete(item) {
				console.log(item, '删除信息');
				uni.showModal({
					title: '删除',
					content: '请确认是否删除组局草稿',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确认',
					success: async res => {
						if (res.confirm) {
							let res = await this.$api.deleteGroupInfoById(item.name)
							if (res.success) {
								uni.showToast({
									title: '删除成功',
									icon: 'none'
								});
								this.resetList()
							}
						} else if (res.cancel) {
							uni.showToast({
								title: '已取消删除',
								icon: 'none'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});

			},

			handleItem(data) {
				console.log(data, '点击跳转编辑');
				let url = "/pagesParty/party/editParty/editParty?id=" + data.id
				this.$goToPage(url)

			}

		}
	}
</script>

<style lang="scss">
	.sendPartyWp {
		padding-top: 1rpx;
		min-height: 100vh;
		background-color: #f7f8fa;

	}
</style>